//
//  WJPublishPicCell.m
//  WJBSApp
//
//  Created by dllo on 16/8/1.
//  Copyright © 2016年 王景伟. All rights reserved.
//

#import "WJPublishPicCell.h"

@interface WJPublishPicCell ()

@property (nonatomic, retain) WJBaseView *belowView;

@property (nonatomic, retain) WJBaseLable *textLab;

@property (nonatomic, retain) WJBaseLable *timeLable;

@property (nonatomic, retain) WJBaseButton *deleteButton;

@end

@implementation WJPublishPicCell



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.belowView = [[WJBaseView alloc]init];
        [self.contentView addSubview:self.belowView];
        
        self.timeLable = [[WJBaseLable alloc]initWithFrame:CGRectZero dayBgColor:LABLECOLOR nightBgColor:FORBLACKCOLOR dayTextColor:BSGrayColor nightTextColor:BSWhiteColor];
        self.timeLable.font = [UIFont systemFontOfSize:13];
        [self.belowView addSubview:self.timeLable];
        
        self.deleteButton = [WJBaseButton buttonWithType:UIButtonTypeCustom];
        [self.deleteButton setImage:[UIImage imageNamed:@"Delete.png"] forState:0];
        [self.deleteButton addTarget:self action:@selector(deleteAct:) forControlEvents:1<<6];
        [self.belowView addSubview:self.deleteButton];
        
        self.textLab = [[WJBaseLable alloc]init];
        self.textLab.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:self.textLab];
        
        self.picImageView = [[WJBaseImageView alloc]init];
        [self.contentView addSubview:self.picImageView];
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.belowView.frame = CGRectMake(0, 10, WIDTH, 40);
    
    self.timeLable.frame = CGRectMake(10, 10, 150 , 30);
    
    self.deleteButton.frame = CGRectMake(WIDTH - 60, 5, 30, 30);
    
    NSDictionary *dic = @{NSFontAttributeName:[UIFont systemFontOfSize:16]};
    CGRect rect = [self.textLab.text boundingRectWithSize:CGSizeMake(WIDTH - 20, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    
    self.textLab.frame = CGRectMake(10, 50, WIDTH - 20, rect.size.height);
    
    UIImage *image = [UIImage imageWithData:self.model.picData];
    
    CGFloat height = (WIDTH - 20) * image.size.height / image.size.width;
    
    self.picImageView.frame = CGRectMake(10, 60 + rect.size.height , WIDTH - 20, height);
}

- (void)setModel:(WJPublishModel *)model
{
    _model = model;
    
    self.textLab.text = model.text;
    
    self.timeLable.text = model.nowTime;
    
    self.picImageView.image = [UIImage imageWithData:self.model.picData];
}

- (void)deleteAct:(WJBaseButton *)button
{
    NSLog(@"点击删除");
    if (self.Block) {
        self.Block(self.model.nowTime);
    }

}




@end
